feat: add encode_json and loads helpers for better JSON null support#57
Open
adityak74 wants to merge 2 commits intotoon-format:mainfrom
Open
feat: add encode_json and loads helpers for better JSON null support#57adityak74 wants to merge 2 commits intotoon-format:mainfrom
adityak74 wants to merge 2 commits intotoon-format:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds JSON integration helpers to toon_format to streamline encoding JSON strings (including JSON null) into TOON, and introduces integration tests to validate the flow.
Changes:
- Added
toon_format.loads()(wrapper aroundjson.loads) andtoon_format.encode_json()(JSON string → parsed Python →encode()). - Re-exported the new helpers at the top-level
toon_formatpackage. - Added new integration tests covering
nullhandling in objects and arrays.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/toon_format/utils.py |
Introduces loads() and encode_json() helpers and exports them from the utils module. |
src/toon_format/__init__.py |
Re-exports the new helpers in the public package API. |
tests/test_json_integration.py |
Adds integration tests for JSON null → Python None → TOON null behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Update utils.py module docstring to include JSON helpers - Fix circular import of encode in utils.py - Remove unused imports and print statements in tests - Fix formatting in tests using ruff
Contributor
|
@toon-format/python-maintainers, this PR introduces new functions, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Closes #49
Description
Support JSON
nullvalues in thetoon-pythonencoding flow by adding helper functions to automatically convert JSONnullto PythonNoneduring encoding. This improves the developer experience when working with LLM tool outputs, APIs, and logs where JSONnullis the standard for missing values.Type of Change
Changes Made
toon_format.loads(json_string)as a convenience wrapper aroundjson.loadsto ensure a "TOON-friendly" integration flow.toon_format.encode_json(json_string)to directly encode a JSON string into TOON format, handlingnulltoNoneconversion automatically.loadsandencode_jsonin the top-leveltoon_formatpackage.tests/test_json_integration.pycoveringnullvalues in objects and arrays.SPEC Compliance
Testing
Pre-submission Checklist
Breaking Changes
Additional Context
This implementation follows the proposed solution in the issue to provide a standard utility for JSON integration, reducing the need for manual pre-processing of data containing
nullvalues.